<?php
class Uri {
    static private $Router;
    
    static function init( Router $r ) {
        self::$Router = $r;
    }
    
    /**
     * Redirects user to $location after $delay seconds
     * @param $location
     * @param $delay
     */
    static function redirect( $location, $delay = null ) {
        if( $delay === null ) {
            header( 'Location: ' . $location );
            exit;
        }
        header( 'Refresh: ' . $delay . '; url=' . $location );
        exit;
    }
    
    /**
     * Builds local uri or returns base uri
     * @param unknown_type $path
     */
    static function build( $path = null ) {
        $index = Config::get( 'index_page', 'config' );
        if(Config::get( 'index_page', 'config' ) != '')
            $index .= '/';
        if( is_array( $path ) ) {
            $tmp = array();
            foreach( $path as $k => $v )
                $tmp[] = urlencode( $k ) . '/' . urlencode( $v );
            $path = implode( '/', $tmp );
        }
        return URLPATH . $index . $path;
    }
    
    static function base_path( ) {
        return URLPATH;
    }
    
    static function static_path() {
        return URLSTATIC;
    }
    
    /**
     * Returns current uri
     */
    static function current() {
        return self::$Router -> getUriString();
    }
}